﻿namespace zlhis_restful.Common
{
    using System;

    /// <summary>
    /// Defines the <see cref="ResultJson" />.
    /// </summary>
    public class ResultJson
    {
        /// <summary>
        /// Gets or sets the code
        /// 编码.
        /// </summary>
        public string code { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether success
        /// 调用是否成功.
        /// </summary>
        public bool success { get; set; }

        /// <summary>
        /// Gets or sets the data
        /// 数据.
        /// </summary>
        public object data { get; set; }

        /// <summary>
        /// Gets or sets the message
        /// 消息.
        /// </summary>
        public string message { get; set; }

        /// <summary>
        /// Gets or sets the restime
        /// 数据返回时间.
        /// </summary>
        public string restime { get; set; }

        /// <summary>
        /// The SetSuccessResult.
        /// </summary>
        /// <param name="resData">The resData<see cref="string"/>.</param>
        /// <returns>The <see cref="ResultJson"/>.</returns>
        public ResultJson SetSuccessResult(object resData)
        {
            code = "2000";
            success = true;
            data = resData;
            message = "接口调用成功";
            restime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
            return this;
        }

        /// <summary>
        /// The SetFailedResult.
        /// </summary>
        /// <param name="errCode">The errCode<see cref="string"/>.</param>
        /// <param name="errMsg">The errMsg<see cref="string"/>.</param>
        /// <param name="e">The e<see cref="Exception"/>.</param>
        /// <returns>The <see cref="ResultJson"/>.</returns>
        public ResultJson SetFailedResult(string errCode, string errMsg, Exception e)
        {
            code = errCode;
            success = true;
            data = e.Message;
            message = errMsg;
            restime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
            return this;
        }
    }
}
